<?php
/**
 * @version:		$Id: browserDetect.php 2 2011-07-26 00:59:53Z epatarroyo $
 * @copyright:		Copyright (C) 2010 OpenWeb Software. All rights reserved.
 * @license:		GNU/GPL
 * This version may have been modified pursuant to the GNU General Public License,
 * and as distributed it includes or is derivative of works licensed under the
 * GNU General Public License or other free or open source software licenses.
 */

/* Funcion para detectar la version de Internet Explorer */
function ieversion() {
  preg_match('/MSIE ([0-9]\.[0-9])/',$_SERVER['HTTP_USER_AGENT'],$reg);
  if(!isset($reg[1])) {
    return -1;
  } else {
    return floatval($reg[1]);
  }
}

function browserDetect() {
  
  $browser = "other";
  
  $detect = new Mobile_Detect();
  if($detect->isMobile()){
    if ($detect->isAndroid()) {
        $browser = "mobile-android";
    }
    if ($detect->isBlackberry()) {
        $browser = "mobile-blackberry";
    }
    if ($detect->isIphone()) {
        $browser = "mobile-iphone";
    }
    if ($detect->isIpad()) {
        $browser = "mobile-ipad";
    }
    if ($detect->isOpera()) {
        $browser = "mobile-opera";
    }
    if ($detect->isPalm()) {
        $browser = "mobile-palm";
    }
    if ($detect->isWindows()) {
        $browser = "mobile-windows";
    }
    if ($detect->isGeneric()) {
        $browser = "mobile-generic";
    }
  } else {
  
    $browsers = array(
    	"Firefox",
      "MSIE",
      "Safari",
      "Chrome",
      "Opera",
      "Lynx"
  	);
  	
  	foreach ($browsers as $b) {
  	  if(preg_match('/' . $b . '/', $_SERVER['HTTP_USER_AGENT'])){
  	    $browser = $b;
  	  }
  	}
  	
  	if ($browser == "MSIE"){
      $browser .= ieversion();
  	}
  }
	return $browser; 
}